namespace GPSTrackingReports
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using Telerik.Reporting;
    using Telerik.Reporting.Drawing;
    using System.Data;

    using System.Web;

    using System.Data;
    

    /// <summary>
    /// Summary description for Catalog_StatisticsByItemView.
    /// </summary>
    public partial class Catalog_StatisticsByPieItemView : Telerik.Reporting.Report
    {

        int companyID = 3;
        DateTime beginDate = DateTime.Parse("2014-08-01");
        DateTime endDate = DateTime.Parse("2014-09-30");

        public Catalog_StatisticsByPieItemView()
        {
            //
            // Required for telerik Reporting designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        public void SetParameters(DateTime beginDate, DateTime endDate, int companyID, Image logo)
        {
            this.companyID = companyID;
            this.beginDate = beginDate;
            this.endDate = endDate;

            sqlDataSource1.Parameters["@BeginDate"].Value = beginDate;
            sqlDataSource1.Parameters["@EndDate"].Value = endDate;
            sqlDataSource1.Parameters["@CompanyID"].Value = companyID;

            pictureBox1.Value = logo;
            pictureBox1.Width = Unit.Pixel(logo.Width);
            pictureBox1.Height = Unit.Pixel(logo.Height);
        }

        private void chart1_NeedDataSource(object sender, EventArgs e)
        {
            try
            {
                Telerik.Reporting.Processing.Chart chart = sender as Telerik.Reporting.Processing.Chart;
                //chart.DataSource = this.sqlDataSource1;


                DataTable table = new DataTable();
                table.Columns.Add("VisorValue", typeof(string));
                table.Columns.Add("allHours", typeof(double));


                //DataView dv = (DataView)sqlDataSource1.Select(Telerik.UI.DataSourceSelectArguments.Empty);
                //int reorderedProducts = (int);
                //if (reorderedProducts > 0)
                //{
                //Label1.Text = "Number of products on reorder: " + reorderedProducts;
                //     table.Rows.Add(new object[] { dv.Table.Rows[0]["VisorValue"].ToString(), float.Parse(dv.Table.Rows[0]["allMinutes"].ToString()) });
                //}
                //else
                //{
                //Label1.Text = "No products on reorder.";
                //}




                System.Data.Objects.ObjectResult<GPSTrackingReports.EntityFrameworkManager.Report_Catolog_GetStatisticsByItemView_Result> result = new GPSTrackingReports.EntityFrameworkManager.FalconSystemDBEntities1().Report_Catolog_GetStatisticsByItemView(companyID, beginDate, endDate, null, null);
                //DataTable dt = GPSTrackingDBV2Custom.Data.DataRepository.CatalogStatistics.GetAll(companyID, beginDate, endDate);

                //table.Rows.Add(new object[] { "Menu > Blu-Ray", 10 });

                //foreach (DataRow row in dt.Rows)
                //{
                //    table.Rows.Add(new object[] { row["VisorValue"].ToString(), float.Parse(row["Minutes"].ToString()) });
                //}

                foreach (GPSTrackingReports.EntityFrameworkManager.Report_Catolog_GetStatisticsByItemView_Result row in result)
                {
                    table.Rows.Add(new object[] { row.VisorValue, row.allMinutes });
                }





                //table.Rows.Add(new object[] { "Menu > Blu-Ray", 10 });
                //table.Rows.Add(new object[] { "Menu > DVD", 20 });
                //table.Rows.Add(new object[] { "Menu > Juegos", 30 });

                Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart)chart.ItemDefinition;
                Telerik.Reporting.Charting.ChartSeries s = chartDef.Series[0];
                s.Clear();
                s.Appearance.LegendDisplayMode = Telerik.Reporting.Charting.ChartSeriesLegendDisplayMode.ItemLabels;
                foreach (DataRow row in table.Rows)
                {
                    Telerik.Reporting.Charting.ChartSeriesItem item = new Telerik.Reporting.Charting.ChartSeriesItem();
                    item.YValue = (double)row["allHours"];
                    item.Name = (string)row["VisorValue"];
                    //item.Label.TextBlock.Text = (string)row["VisorValue"] + " - #Y";
                    item.Label.TextBlock.Text = "#Y";
                    s.Items.Add(item);
                }
            }
            catch (Exception ex) { }
        }

        private void chart1_ItemDataBound(object sender, EventArgs e)
        {
          
        }
    }
}